package br.com.sig.security;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;

import org.jboss.seam.international.status.Messages;
import org.jboss.seam.international.status.builder.BundleKey;
import org.jboss.seam.security.events.AlreadyLoggedInEvent;
import org.jboss.seam.security.events.LoggedInEvent;
import org.jboss.seam.security.events.LoginFailedEvent;
import org.jboss.seam.security.events.NotLoggedInEvent;
import org.jboss.solder.core.Requires;

@ApplicationScoped
@Requires("org.jboss.seam.international.status.Messages")
public class SecurityMessages {

	public void addLoginFailedMessage(@Observes LoginFailedEvent event, Messages messages) {
		messages.info(new BundleKey("messages", "login.failed"));
	}

	public void addLoginSuccessMessage(@Observes LoggedInEvent event, Messages messages, @Identity BaseIdentity identity) {
		messages.info(new BundleKey("messages", "login.successful"), identity.getUser().getId());
	}

	public void addAlreadyLoggedInMessage(@Observes AlreadyLoggedInEvent event, Messages messages) {
		messages.info(new BundleKey("messages", "already.logged.in"));
	}

	public void addNotLoggedInMessage(@Observes NotLoggedInEvent event, Messages messages) {
		messages.info(new BundleKey("messages", "not.logged.in"));
	}
}